package net.optix.ip.commands
{
	import com.adobe.cairngorm.business.Responder;
	import com.adobe.cairngorm.commands.Command;
	import com.adobe.cairngorm.control.CairngormEvent;
	
	import net.optix.ip.business.*;
	import net.optix.ip.events.AddClientEvent;
	import net.optix.ip.model.ModelLocator;

	public class AddClientCommand implements Command, Responder
	{
		// attributes ============================
		private var model : ModelLocator = ModelLocator.getInstance();


		// functions ============================
		public function execute( event:CairngormEvent ) : void
		{
			var myEvent:AddClientEvent = AddClientEvent( event );
			
			var delegate:UserDelegate = new UserDelegate();     
			delegate.addClient( this , myEvent.vo , myEvent.firmID);
		}
		
		//----------------------------------------------------------------------------
		public function onResult( event : * = null ) : void
		{
			trace(event.result+"   add client");
			var result:int	=	event.result.result;
			switch(result)
			{
				case -2:
					model.result	=	"Access Denied .";
					break;
				case 0:
					model.result	=	"The email is used,try other";
					break;
				case -1:
					model.result	=	"The email is used,try other";
					break;
				case 1:
					model.result	=	"Successfully add client";
					model.close		=	"no";
					model.close		=	"yes";
					break;
				case 2:
					model.result	=	"Successfully add client";
					model.close		=	"no";
					model.close		=	"yes";
					break;	
			}
			model.bSubmit	=	true;
		}
		
		//----------------------------------------------------------------------------
		public function onFault( event : * = null ) : void
		{
			trace(event);
			model.result	=	"Program error!";
			
			model.bSubmit	=	true;
		}

	}
}